import gc

import ujson


def fengxian(allDate):
    l = []
    list = []
    li = []
    li1 = []
    li2 = []
    li3 = []
    for i in range(len(allDate)):
        if len(allDate[i]['os']) != 0:
            os = allDate[i]['os']

            for j in range(len(os)):
                gen = os[j]['name']
                list.append(gen)
                del j
                gc.collect()
        del i
        gc.collect()
    for i in list:
        print(i)
        #if i.startswith('Linux'):
        #    li1.append(i)
        #elif i.startswith('Microsoft'):
        #    li2.append(i)
        #elif i.startswith('Apple'):
        #    li3.append(i)
        #else:
        #    continue
    for i in li1:
        with open("../OS_linux.json", encoding="utf-8") as fi:
            for line in fi:
                line = ujson.loads(line)
                if i.find(line['Version']) != -1:
                    print(line['Version'])
                    print(line['Vulnerability Type'])
                    l.append(line['Vulnerability Type'])
                    print(l)
                    break
                del line
                gc.collect()
    for i in li2:
        with open("../OS_microsoft.json", encoding="utf-8") as fi:
            for line in fi:
                line = ujson.loads(line)
                if i.find(line['Version']) != -1:
                    print(line['Version'])
                    print(line['Vulnerability Type'])
                    l.append(line['Vulnerability Type'])
                    print(l)
                    break
                del line
                gc.collect()
    for i in li3:
        with open("../OS_apple.json", encoding="utf-8") as fi:
            for line in fi:
                line = ujson.loads(line)
                if i.find(line['Version']) != -1:
                    print(line['Version'])
                    print(line['Vulnerability Type'])
                    l.append(line['Vulnerability Type'])
                    print(l)
                    break
                del line
                gc.collect()

    return l
